package com.zhuchaooasystem.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.zhuchaooasystem.R;

/**
 * Created by zhangyajiang on 2017/1/11.
 */

public class PurchaseDialog extends AlertDialog {

    private TextView txt_title;
    private EditText et_content;
    private Button btn_ok;
    private Button btn_cancle;

    //----
    private OnViewClickListener listenner;

    public PurchaseDialog(Context context) {
        super(context);
    }

    protected PurchaseDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public PurchaseDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            setContentView(R.layout.dlg_purchase);
            //----
            txt_title = (TextView) findViewById(R.id.dialog_purchase_tv_title);
            et_content = (EditText) findViewById(R.id.dialog_purchase_et_content);
            btn_ok = (Button) findViewById(R.id.dialog_purchase_tv_ok);
            btn_cancle = (Button) findViewById(R.id.dialog_purchase_tv_cancel);
            btn_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listenner != null) {
                        listenner.onClickOk(et_content.getText().toString().trim());
                    } else {
                        dismiss();
                    }
                }
            });
            btn_cancle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listenner != null) {
                        listenner.onClickCancel(PurchaseDialog.this);
                    } else {
                        dismiss();
                    }
                }
            });
        } catch (Exception e) {
        }
    }

    public void setTextTitle(String title) {
        if (null != txt_title) {
            txt_title.setText(title);
        }
    }

    public interface OnViewClickListener {
        void onClickOk(String str);

        void onClickCancel(PurchaseDialog dialog);
    }

    public void setOnViewClickListener(OnViewClickListener listener) {
        this.listenner = listener;
    }
}
